package train48days;
import java.util.*;
public class 查找两个字符串ab中最长的公共子串 {
    //动态规划
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s1 = sc.next();
            String s2 = sc.next();
            if (s1.length()<s2.length()){
                System.out.println(getmaxsubString(s1,s2));
            }else {
                System.out.println(getmaxsubString(s2,s1));
            }
        }
    }
    private  static String getmaxsubString(String s1,String s2){
        char[] arr1 = s1.toCharArray();
        char[] arr2 = s2.toCharArray();
        int leng1 = arr1.length;
        int leng2 = arr2.length;
        int start = 0;
        int maxLen = 0;
        int[][] dp = new int[leng1+1][leng2+1];
        for (int i = 1; i <=leng1 ; i++) {
            for (int j = 1; j <=leng2 ; j++) {
                if (arr1[i-1]==arr2[j-1]){
                    dp[i][j] = dp[i-1][j-1]+1;
                    if (maxLen<dp[i][j]){
                        maxLen= dp[i][j];
                        start=i-maxLen;
                    }
                }
            }
        }
        return s1.substring(start,start+maxLen);
    }


//    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
//        while (in.hasNext()) {
//            String s1 = in.nextLine();
//            String s2 = in.nextLine();
//            String max = s1.length() >= s2.length() ? s1 : s2;
//            String min = s1.length() >= s2.length() ? s2 : s1;
//            int l = 0;
//            String s = "";
//            for (int i = 0; i < min.length(); i++) {
//                for (int j = i + 1; j <= min.length(); j++) {
//                    if (max.contains(min.substring(i, j)) && j - i > l) {
//                        l = j - i;
//                        s = min.substring(i, j);
//                    }
//                }
//            }
//            System.out.println(s);
//        }
//    }
}
